import java.util.Scanner;

public class Main2 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s = in.nextLine();
        int k = in.nextInt();
        int len = 0;
        int[] idx = new int[26];
        String s1 = s.toLowerCase();
        int l = 0, r = 0;
        while (r < s1.length()) {
            char c = s1.charAt(r);
            if (c >= 'a' && c <= 'z') {
                idx[c - 'a']++;
                if (idx[c - 'a'] > 2) {// 如果超过了
                    len = Math.max(len, r - l);
                    while (l < r && idx[c - 'a'] > 2) {
                        if (s1.charAt(l) >= '0' && s1.charAt(l) <= '9') {
                            l++;
                            continue;
                        }
                        idx[s1.charAt(l) - 'a']--;
                        l++;
                    }
                    while (s1.charAt(l) >= '0' && s1.charAt(l) <= '9') {
                        l++;
                    }
                }
            }
            r++;
        }
        System.out.println(len);
    }
}
